#ifndef SIMPLEFTPWIDGET_H
#define SIMPLEFTPWIDGET_H

#include "qtreewidget.h"
#include <QFtp>
#include <QMainWindow>
#include <QTemporaryFile>

namespace Ui {
class SimpleFtpWidget;
}

enum GetType {
    Download,
    Content
};

class SimpleFtpWidget : public QWidget
{
    Q_OBJECT

public:
    explicit SimpleFtpWidget(QWidget *parent = nullptr);
    ~SimpleFtpWidget();

signals:
    void onFtpOpen(QString name, QString conetent);

private slots:
    void on_btn_connect_clicked();
    void on_btn_up_clicked();

private slots:
    void connectToFtp();

    void slot_itemActivated(QTreeWidgetItem *item, int column);
    void slot_commandFinished(int commandId, bool error);
    void slot_listInfo(const QUrlInfo &urlInfo);
    void slot_dataTransferProgress(qint64 readBytes, qint64 totalBytes);


    void on_treeWidget_customContextMenuRequested(const QPoint &pos);

private:
    QString toSpecial(const QString &input);
    QString fromSpecial(const QString &input);

private:
    Ui::SimpleFtpWidget *ui;

    QFtp *ftp;
    QString m_ftpPath;
    QHash<QString, bool> m_isDirectory;
    QHash<QString, QString> m_latin1FileMap;
    QHash<QString, QTemporaryFile*> m_temporary;

    QTemporaryFile *tmpfile;

    GetType m_get_type;
};

#endif // SIMPLEFTPWIDGET_H
